package com.hyz.service.impl;

import com.hyz.pojo.AssetImport;
import com.hyz.pojo.AssetImportResultEnum;
import com.hyz.pojo.AssetLog;
import com.hyz.service.AssetLogService;
import com.hyz.service.AssetManagerService;
import com.hyz.util.GetValue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author HGD
 * @date 2022/10/3 23:49
 */
@Service
public class AssetManagerServiceImpl implements AssetManagerService {
    @Autowired
    private AssetLogService service;
    @Autowired
    private GetValue getValue;

    @Override
    public void batchInsertAssetLogByAssetImports(List<AssetImport> assetImports) {
        List<AssetLog> assetLogs = new ArrayList<>();
        for (AssetImport assetImport : assetImports) {
            AssetLog assetLog = new AssetLog();
            assetLog.setId(getValue.getUuid());
            assetLog.setAssetId(assetImport.getAssetId());
            assetLog.setRepositoryId(assetImport.getRepositoryId());
            assetLog.setResult(assetImport.getResult().getValue());
            assetLogs.add(assetLog);
        }
        System.out.println(assetLogs);
        service.saveBatch(assetLogs);
    }
}
